<?php

namespace app\admin\model;

use think\Model;


class Dvisiting extends Model
{





    // 表名
    protected $name = 'visiting';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'between_time_text',
        'add_time_text'
    ];
    public function getBetweenTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['between_time']) ? $data['between_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getAddTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['add_time']) ? $data['add_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setBetweenTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setAddTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

//        public function getTypeAttr($value, $data){
//        $text = [0 => '个人', 1 => '团体'];
//        return ['val' => $value, 'text' => $text[$value]];
//    }
//    public function getExplainAttr($value, $data){
////        $text = [0 => '不需要', 1 => '需要'];
////        return ['val' => $value, 'text' => $text[$value]];
////    }
//    public function getStatusAttr($value, $data){
//        $text = [0 => '等待预约', 1 => '预约中',2=>'完成参观',3=>"取消预约",4=>"完成评价"];
//        return ['val' => $value, 'text' => $text[$value]];
//    }

    public function users()
    {
        return $this->hasOne('Users', 'id', 'user_id', [], 'LEFT')->setEagerlyType(0);
    }
}
